/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.wholeconsulting.pacc.persistance.database;

import ar.com.wholeconsulting.pacc.model.Fabricante;
import ar.com.wholeconsulting.pacc.persistance.JPASession;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author pable
 */
public class FabricanteImporter extends Importer {

    private static final String QUERY = "select DISTINCT(Fabricante) from Modelos";

    public FabricanteImporter(Connection con) {
        super(con);
    }

    @Override
    protected void importData(ResultSet rs) {
        String fabName=null;
        try {
            Fabricante fab = new Fabricante();
            //fab.setModelos(null);
            fabName = rs.getString(1).trim().toUpperCase();
            if (!fabName.isEmpty()) {
                fab.setNombre(fabName);
                JPASession.getInstance().getManager().persist(fab);
            }
        } catch (SQLException ex) {
            Logger.getLogger(FabricanteImporter.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @Override
    public void importaData() {
        try {
            queryData(QUERY);
        } catch (SQLException ex) {
            Logger.getLogger(FabricanteImporter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
